<%@ page pageEncoding="UTF-8"%>

<%@ taglib uri="/tags/struts-tiles" prefix="tiles"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/struts-nested" prefix="nested"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/trymore" prefix="tm"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix='fmt'%>
<%@ taglib uri="/tags/trymore" prefix="tm"%>

<style>
</style>

<script type="text/javascript">

$(function(){
	//加载上传组件入口文件
	KISSY.use('gallery/form/1.2/uploader/index', function (S, RenderUploader) {
		var ru = new RenderUploader('#j_J_UploaderBtnAttendance', '#j_J_UploaderQueueAttendance',{
			 //服务器端配置
			serverConfig:{
				//处理上传的服务器端脚本路径
				action:"file-upload?noattach=y&noentity=y&json"
			},
			//验证配置
		    authConfig: {
		        require:[true,"必须至少上传一个文件！"],
		        max:[1, "最多上传{max}个文件！"],
		        allowRepeat:[false, "该文件已经存在！"],
		        allowExts:[
		            {"desc":"xls", "ext":"*.xls;"}, "只支持xls格式文件.."
		        ]
		    },
			// 文件域
			name:"Filedata",
			//用于放服务器端返回的url的隐藏域
			urlsInputName:"fileUrls"
			<c:if test="${entity ne null && fn:length(entity.attachFiles) gt 0}">
			// 用于数据展现
			,restoreHook:"#jp_J_UploaderRestoreAttendance"
			</c:if>
		});
		
		ru.on('init', function (ev) {
			//上传组件实例
			var uploader = ev.uploader;
			//上传按钮实例
			var button = uploader.get('button');
			
			uploader.on('start', function(ev) {
				$("#upload_status").html("文件上传中...").fadeIn("slow");
			});
			
			uploader.on('success', function (ev) {
				var feedback = ev.result;
				var file_id = feedback.data.id;
				if (file_id) {
					$("#fileIds").val($("#fileIds").val() == "" ? file_id : ($("#fileIds").val() + "," + file_id));
				}
				
				$("#upload_status").html("文件上传成功了, 请点击导入按钮进行数据导入...").fadeIn("slow");
				
			});
			
			uploader.on('error', function (ev) {
				alert("文件上传失败:" + ev.result.message);
			});
			
		});
	});
	
	$("#importProf").click(function(){
		if ($("#fileUrls").val() == "") {
			alertMsg.error("请先上传需要导入的Excel文件..");
		} else {
			var form = $("#formImport").get(0);
			$.ajax({
				type: form.method || 'POST',
				url:$(form).attr("action"),
				data:$(form).serializeArray(),
				dataType:"json",
				cache: false,
				success: function(json) {
					DWZ.ajaxDone(json);
					$.pdialog.closeCurrent();
					navTab.reload();
				},
				error: DWZ.ajaxError
			});
		}
	});
	
});

</script>
<script type="text/uploader-restore" id="jp_J_UploaderRestoreAttendance">
${tm:fileRestore(entity['attachFiles'])}
</script>

<form method="post" action="app/proficient.do?action=actionImportProficient" id="formImport" 
	class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
	<div class="pageContent">
		<div class="pageFormContent" layoutH="56">
			<table class="searchContent">
				<tr>
					<td><label style="width: 80px">上传文件：</label></td>
					<td>
						<a id="j_J_UploaderBtnAttendance" class="uploader-button" style="width:90px" href="javascript:void(0);">请选择数据文件 </a>
						<ul id="j_J_UploaderQueueAttendance" class="uqueen" style="width:auto;"></ul>
						<div id="J_Panel" class="event-panel"></div>
						<input type="hidden" name="fileUrls" id="fileUrls" />
						<input type="hidden" name="fileIds" id="fileIds" />
					</td>
				</tr>
				<tr>
					<td><label style="width: 80px">重复数据：</label></td>
					<td>
						<input style="margin-top:0;vertical-align:middle" type="radio" name="mode" value="1" checked /><span>覆盖</span>
						<input style="margin-top:0;vertical-align:middle" type="radio" name="mode" value="2" /><span>创建</span>
					</td>
				</tr>
			</table>
			<div id="upload_status" style="margin: 10px 0; padding: 0 5px; line-height: 20px; color: green; display: none;"></div>
			<div style="text-align:right; line-height: 30px; color: #CF0800; margin: 5px 0">
				小贴士: 姓名相同的专家, 则被视为重复数据..
			</div>
		</div>
		
		<div class="formBar">
			<ul>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
				<li id="btn_allocate">
					<div class="buttonActive"><div class="buttonContent"><button type="button" id="importProf">导入</button></div></div>
				</li>
			</ul>
		</div>
	</div>
</form>